package cashpointer.core.model;

import com.thoughtworks.xstream.annotations.XStreamAlias;

/**
 * Klasa do przechowywania adresu bankomatu.
 * @author wojciech topolski
 * @version 2009-03-25
 */
@XStreamAlias("Address")
public class Address {

    // Miasto.
    @XStreamAlias("city")
    private String city;
    private static int CITY_LENGTH = 100;

    // Powiat.
    @XStreamAlias("county")
    private String county;
    private static int COUNTRY_LENGTH = 100;

    // Wojewodztwo.
    @XStreamAlias("region")
    private String region;
    private static int REGION_LENGTH = 100;

    // Ulica.
    @XStreamAlias("street")
    private String street;
    private static int STREET_LENGTH = 100;

    // Info.
    @XStreamAlias("info")
    private String info;
    private static int INFO_LENGTH = 100;

    // Polozenie geograficzne.
    @XStreamAlias("GeoPoint")
    private GeoPoint geoPoint;

    /**
     * Konstruktor.
     */
    public Address() {
    }

    /**
     * Zwraca miasto.
     * @return String
     */
    public String getCity() {
        return city;
    }

    /**
     * Pobiera miasto.
     * @param city String
     */
    public void setCity(String city) {
        if (city != null) {
            this.city = (city.length() > CITY_LENGTH) ? city.substring(0, CITY_LENGTH) : city;
        }
    }

    /**
     * Zwraca wojewodztwo.
     * @return String
     */
    public String getRegion() {
        return region;
    }

    /**
     * Pobiera wojewodztwo.
     * @param region String
     */
    public void setRegion(String region) {
        if (region != null) {
            this.region = (region.length() > REGION_LENGTH) ? region.substring(0, REGION_LENGTH) : region;
        }
    }

    /**
     * Zwraca ulice.
     * @return String
     */
    public String getStreet() {
        return street;
    }

    /**
     * Pobiera ulice.
     * @param street String
     */
    public void setStreet(String street) {
        if (street != null) {
            this.street = (street.length() > STREET_LENGTH) ? street.substring(0, STREET_LENGTH) : street;
        }
    }

    /**
     * Zwraca obiekt polozenia geograficznego
     * @return GeoPoint
     */
    public GeoPoint getGeoPoint() {
        return geoPoint;
    }

    /**
     * Pobiera obiekt polozenia geograficznego.
     * @param geoPoint GeoPoint
     */
    public void setGeoPoint(GeoPoint geoPoint) {
        this.geoPoint = geoPoint;
    }

    /**
     * Zwraca nazwe powiatu.
     * @return String
     */
    public String getCounty() {
        return county;
    }

    /**
     * Pobiera nazwe powiatu.
     * @param county String
     */
    public void setCounty(String county) {
        if (county != null) {
            this.county = (county.length() > COUNTRY_LENGTH) ? county.substring(0, COUNTRY_LENGTH) : county;
        }
    }


    /**
     * Zwraca dodatkowe informacje.
     * @return String
     */
    public String getInfo() {
        return info;
    }

    /**
     * Pobiera dodatkowe informacje.
     * @param info String
     */
    public void setInfo(String info) {
        if (info != null) {
            this.info = (info.length() > INFO_LENGTH) ? info.substring(0, INFO_LENGTH) : info;
        }
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Address other = (Address) obj;
        if ((this.city == null) ? (other.city != null) : !this.city.equals(other.city)) {
            return false;
        }
        if ((this.region == null) ? (other.region != null) : !this.region.equals(other.region)) {
            return false;
        }
        if ((this.street == null) ? (other.street != null) : !this.street.equals(other.street)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 67 * hash + (this.city != null ? this.city.hashCode() : 0);
        hash = 67 * hash + (this.region != null ? this.region.hashCode() : 0);
        hash = 67 * hash + (this.street != null ? this.street.hashCode() : 0);
        return hash;
    }
}
